﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using LinkPointTransaction;
using System.Collections.Specialized;
using System.Configuration;
using SiteManager;
using System.Text;
using System.Data.SqlClient;

using ArbApiSample;
using System.IO;


public partial class Doctor_Doctorsubscription : System.Web.UI.Page
{

    Manager ObjManager = new Manager(true, "ConnectionString");
    Doctor ObjDoctor = new Doctor();
    localFunction drchk = new localFunction();
    int iDoctorid = 0;
    protected bool fIE5;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["userID"].ToString() != "" && Session["userID"] != null)
        {
            iDoctorid = Convert.ToInt32(Session["userID"]);
        }

        // Master.InnerRightBox = false;
        //Master.InnerFeatureDocBox = true;

        //Check Doctor Login
        drchk.checkDoctorLogin(true);

        if (!CheckDoctorExist())
        {
            lblMessage.Text = "You are already registered.";
        }

        if (!Page.IsPostBack)
        {
            //Fill dropdowns
            LoadCommonControls();
        }







    }


    private void LoadCommonControls()
    {
        ObjManager.BindList("select FeatureDocTypeId,FeatureDocType from  tbl_FeatureDocType", "FeatureDocType", "FeatureDocTypeId", ddlFeaturedDocType, "");
        ddlFeaturedDocType.Items.Insert(0, new ListItem("Select", "0"));
        if (!CheckDoctorExist())
        {
            Manager mgr = new Manager(true, "ConnectionString");
            DataSet ds = CustomRepository.CustumDataSetFunction("select * from tbl_doctors where  isdelete=0 and id=" + Convert.ToInt32(Session["userID"]), "tblDoctor");
            string FeatureDocTypeId = Convert.ToString(ds.Tables[0].Rows[0]["FeatureDocTypeId"]);
            ddlFeaturedDocType.SelectedValue = FeatureDocTypeId;
        }
    }


    private bool CheckDoctorExist()
    {
        object objcount = ObjManager.ExecuteScalarQuery("select count(doctorid) from doctorsubscription where doctorid=" + Convert.ToInt32(Session["userID"]));
        if (Convert.ToString(objcount) == "0")
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        SaveDataAfterApproval();
        Response.Redirect("Payment.aspx");
    }


    private bool chechDentistInSub()
    {
        int id = Convert.ToInt32(Session["userID"]);

        object objcount = ObjManager.ExecuteScalarQuery("select count(DoctorId) from DoctorSubscription where DoctorId=" + Convert.ToInt32(Session["userID"]));
        if (Convert.ToString(objcount) == "0")
        {
            return true;
        }
        else
        {
            return false;

        }
    }
    
    private void SaveDataAfterApproval()
    {
        //Write Code to add the processed value in database
        ObjDoctor.DoctorId = iDoctorid;
        ObjDoctor.TransactionId = "111111";
        ObjDoctor.TransactionDate = DateTime.Now.ToString();//need to confirm  which date should be add ?? R_Time or startdate.
        // ObjDoctor.TransactionAmount = txttotal.Text.ToString();
        ObjDoctor.SubscriptionId = "222222";
      //  ObjDoctor.SubscriptionType = rbSubscription.SelectedItem.ToString();
        ObjDoctor.FeaturedocTypeId = Convert.ToInt32(ddlFeaturedDocType.Text);
        //ObjDoctor.SpecialityId = Convert.ToInt32(ddlSpeciality.Text);
        //ObjDoctor.SubSpecialityId = Convert.ToInt32(ddlSubSpeciality.Text);
        //ObjDoctor.photo = ViewState["sfilename"].ToString();
        //ObjDoctor.prof_desc = txtdoctorStatement.Text.Trim().ToString();
        //ObjDoctor.website = txtWebSite.Text.Trim().ToString();
        ObjDoctor.IsCheck = false;
        ObjDoctor.IsCheckTop = false;



        ObjManager.ExecuteScalarQuery("update tbl_doctors set FeatureDocTypeId ='" + ObjDoctor.FeaturedocTypeId + "' where id ='" + ObjDoctor.DoctorId + "'");
        if (chechDentistInSub())
        {
            ObjDoctor.InsertDoctorSubscription();
        }
        else
        {
            ObjManager.ExecuteScalarQuery("Update DoctorSubscription set FeaturedocTypeId='" + ObjDoctor.FeaturedocTypeId + "'  where DoctorId='" + ObjDoctor.DoctorId + "'");
        }

    }

    //private void setvalue()
    //{
    //    SecurePay objSecurepay = new SecurePay();
    //    objSecurepay.Name = txtName.Text;
    //    objSecurepay.Street = txtbaddrnum.Text; ;
    //    objSecurepay.City = txtCity.Text;
    //    objSecurepay.State = ddlState.SelectedItem.Text; //txtState.Text;Commented by Wahaj April 29 2011
    //    objSecurepay.Zip = txtbzip.Text;
    //    objSecurepay.Email = txtEmail.Text;
    //    objSecurepay.Amount = txttotal.Text;
    //    //objSecurepay.CC_Name = ddlCardType.SelectedValue;
    //    objSecurepay.CC_Number = txtcardnumber.Text;
    //    objSecurepay.Month = ddlMonth.SelectedValue;
    //    objSecurepay.Year = ddlYear.SelectedValue;
    //    string period = rbSubscription.SelectedItem.ToString();
    //    objSecurepay.TimeFrame = period;
    //    objSecurepay.Rec_Amount = txttotal.Text;
    //    objSecurepay.Start_Date = DateTime.Now.ToString();
    //    Session["SetValue"] = objSecurepay;
    //}
}
